﻿using System.Linq;
using System.Web.Mvc;
using MemcachedProviders.Cache;
using ProjectYANApi.MemcachedFunction;
using ProjectYANApi.Models;
using YanOnline.Function;
using System.Collections.Generic;
using ProjectYANApi.Function;

namespace ProjectYANApi.Controllers
{
    public class ScheduleCacheController : Controller
    {
        //
        // GET: /ScheduleCache/

        public ActionResult Index()
        {
            return View();
        }

        int PageSize = 30;
        public ActionResult ClearAll()
        {
            clsFunction.SaveLogClearCache("Auto clear cache", "Xóa cache: ClearAll", "Xóa cache: ClearAll",
                System.DateTime.Now.ToString(),
                System.Web.HttpContext.Current.Request.UserHostName);

            //HOMEPAGE
            for (int i = 1; i < 11; i++)
            {
                string strId = MemcachedKey.hstblContentGetHomePage + "_" + i;
                List<ListContent> lst = new List<ListContent>();
                lst = clsFunction.Api_tblContentGetHomePage(PageSize, i);
                DistCache.Remove(strId);
                DistCache.Add(strId, lst);
            }

            //TIN MỚI CẬP NHẬT
            for (int i = 1; i < 11; i++)
            {
                string strId = MemcachedKey.hstblContentGetNewNewsWithPage + "_" + i;
                List<ListContent> lst = new List<ListContent>();
                lst = clsFunction.Api_tblContentGetNewNewsWithPage(PageSize, i);
                DistCache.Remove(strId);
                DistCache.Add(strId, lst);
            }

            //tin theo chuyen mục
            string[] ZoneIDs = { "4", "6", "2", "7", "9", "8", "11", "1" };
            for (int k = 0; k < ZoneIDs.Length; k++)
            {
                for (int i = 1; i < 11; i++)
                {
                    string strId = MemcachedKey.hsApi_tblContentGetByZoneWithPage + "_" + i + "_" + ZoneIDs[k];
                    List<ListContent> lst = new List<ListContent>();
                    lst = clsFunction.Api_tblContentGetByZoneWithPage(PageSize, i, System.Convert.ToInt32(ZoneIDs[k]));
                    DistCache.Remove(strId);
                    DistCache.Add(strId, lst);
                }
            }

            //tin tong hop
            for (int i = 1; i < 11; i++)
            {
                string strId = MemcachedKey.hstblContentGetEnterZoneWithPage + "_" + i;
                List<ListContent> lst = new List<ListContent>();
                lst = clsFunction.Api_tblContentGetEnterZoneWithPage(PageSize, i);
                DistCache.Remove(strId);
                DistCache.Add(strId, lst);
            }

            //VIDEO
            for (int i = 1; i < 11; i++)
            {
                string strId = MemcachedKey.hstblContentGetVideoZoneWithPage + "_" + i;
                List<ListContent> lst = new List<ListContent>();
                lst = clsFunction.Api_tblContentGetVideoZoneWithPage(PageSize, i);
                DistCache.Remove(strId);
                DistCache.Add(strId, lst);
            }

            //SAO
            for (int i = 1; i < 11; i++)
            {
                string strId = MemcachedKey.hstblContentGetCelebZoneWithPage + "_" + i;
                List<ListContent> lst = new List<ListContent>();
                lst = clsFunction.Api_tblContentGetCelebZoneWithPage(PageSize, i);
                DistCache.Remove(strId);
                DistCache.Add(strId, lst);
            }

            //MLOG
            for (int i = 1; i < 11; i++)
            {
                string strId = MemcachedKey.hstblContentGetBlogZoneWithPage + "_" + i;
                List<ListContent> lst = new List<ListContent>();
                lst = clsFunction.Api_tblContentGetBlogZoneWithPage(PageSize, i);
                DistCache.Remove(strId);
                DistCache.Add(strId, lst);
            }

            //comic con
            List<tblNews> lstNews = new List<tblNews>();
            lstNews = clsFunction.tblContentNewsSearchTagGetAll("comic con");
            DistCache.Remove(MemcachedKey.hsGetForPartner);
            DistCache.Add(MemcachedKey.hsGetForPartner, lstNews);

            return View();
        }

    }
}
